﻿using System;
using System.Windows.Browser;

namespace SBPweb.PhotoGallery.Client.Utils
{

    public class HtmlElements
    {

        private HtmlElements()
        {
        }

        public static string GetSlidesXmlFromDom(string elementId)
        {
            HtmlDocument doc = HtmlPage.Document;
            HtmlElement slidesElement = FindControlRecursively(doc.Body, elementId);
            return slidesElement.GetProperty("innerHTML").ToString().Trim();
        }

        public static HtmlElement FindControlRecursively(HtmlElement element, string elementId)
        {
            if (element == null)
            {
                return null;
            }
            if (element.Id == elementId)
            {
                return element;
            }
            foreach (HtmlElement hE in element.Children)
            {
                HtmlElement elem = FindControlRecursively(hE, elementId);
                if (elem != null)
                {
                    return elem;
                }
            }
            return null;
        }
        
    }

}
